package com.atguigu.realtime.util;

import com.atguigu.realtime.common.Constant;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author chenlongStart
 * @create 2021-06-29 10:54
 * @desc
 */
public class RedisUtil {

    private static JedisPool pool;

    public static Jedis getRedisClient() {
        if (pool == null) {
            synchronized (RedisUtil.class){
                if (pool == null){
                    JedisPoolConfig conf = new JedisPoolConfig();
                    conf.setMaxTotal(1000);
                    conf.setMaxTotal(100);
                    conf.setMinIdle(10);
                    conf.setMaxWaitMillis(Constant.REDIS_WAIT_TIME);// 从连接池获取对象的时候, 最多等待的时间
                    conf.setTestOnBorrow(true);
                    conf.setTestOnCreate(true);
                    conf.setTestOnReturn(true);
                    pool = new JedisPool(conf,"hadoop162",6379);
                }
            }
        }
        return pool.getResource();
    }

}
